<template>
  <div class="bg">
    <!-- 头部 -->
    <Header title="运维管理—巡检线路"></Header>

    <!-- 搜索栏 -->
    <section class="search_bar">
      <LInput label="路线名称" v-model="name"></LInput>
      <LButton label="+新增" style="margin-left: 16px" @click="repairDialog = true"></LButton>
      <LButton label="查询数据" style="margin-left: 16px"></LButton>
      <LButton label="重置条件" style="margin-left: 16px" @click="clearSelected"></LButton>
    </section>
    <!-- 表格 -->
    <el-table :data="tData" style="width: 100%" border>
      <el-table-column prop="a" label="路线编码" />
      <el-table-column prop="b" label="路线名称" />
      <el-table-column prop="c" label="备注" />
      <el-table-column label="操作" width="210">
        <template #default>
          <el-button type="success" size="mini" @click="repairDialog2 = true">查看</el-button>
          <el-button type="primary" size="mini" @click="repairDialog3 = true">编辑</el-button>
          <el-button type="danger" size="mini" @click="del">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹出框：新增 -->
    <div v-dialogdrag>
      <el-dialog v-model="repairDialog" title="新增" width="50%" @close="repairDialogClose">
        <div class="dialog-border">
          <el-form label-width="100px" :model="repairForm" ref="repairFormRef" :rules="repairFormRules" size="small">
            <div class="row-1">
              <el-form-item label="路线编号" prop="no" style="width:100%">
                <el-input v-model="repairForm.no"></el-input>
              </el-form-item>
              <el-form-item label="路线名称" prop="no" style="width:100%">
                <el-input v-model="repairForm.no"></el-input>
              </el-form-item>
            </div>
            <div style="padding: 0 2vw 0 0">
              <el-form-item label="备注" prop="mark" style="width:100%">
                <el-input v-model="repairForm.mark" type="textarea" :rows="1"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="dialog-border-padding">
            <div style="padding: 1vh 0;text-align:center">已选设备</div>
            <div style="position:relative">
              <el-button type="primary" size="mini" style="position:absolute;right:0vw;bottom:0.5vh" @click="repairDialog1=true">增加</el-button>
            </div>
            <el-table :data="tableData" style="width: 100%" border :default-sort="{ prop: 'a', order: 'ascending' }">
              <el-table-column prop="a" label="设备编号" width="110" />
              <el-table-column prop="b" label="设备名称" />
              <el-table-column prop="c" label="规格型号" />
              <el-table-column prop="d" label="安装地址" />
              <el-table-column prop="e" label="设备类型" />
              <el-table-column label="操作" width="190">
                <template #default>
                  <el-button type="primary" size="mini" @click="repairDialog4=true">编辑巡检步骤</el-button>
                  <el-button type="danger" size="mini">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairSureBtn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- “新增”弹出框里的弹框1：设备列表 -->
    <div v-dialogdrag class="pop-2">
      <el-dialog v-model="repairDialog1" title="选择设备" width="50%" @close="repairDialog1Close()" :rules="repairForm1Rules">
        <el-form ref="repairForm1Ref" :model="repairForm1" label-width="50px" size="small">
          <el-form-item label="搜索" prop="search" style="width: 50%">
            <el-input v-model="repairForm1.search"></el-input>
          </el-form-item>
        </el-form>
        <el-table :data="subTable1" style="width: 100%" border ref="subTable1Ref" @selection-change="subTable1Selected" :default-sort="{prop:'a',order:'ascending'}">
          <el-table-column type="selection" width="35" />
          <el-table-column prop="a" label="设备编号" />
          <el-table-column prop="b" label="设备名称" />
          <el-table-column prop="c" label="规格型号" />
          <el-table-column prop="d" label="安装地址" />
          <el-table-column prop="e" label="设备类型" />
        </el-table>
        <el-pagination small background layout="prev, pager, next" :total="200000">
        </el-pagination>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairDialog1SureBtn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog1CalcBtn()">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- “新增”弹出框里的弹框2：巡检步骤列表 -->
    <div v-dialogdrag class="pop-2">
      <el-dialog v-model="repairDialog4" title="选择步骤列表" width="60%" @close="repairDialog4Close()" :rules="repairForm4Rules">
        <div class="dialog-border">
          <div style="display:flex">
            <el-tabs type="border-card" style="width:550px">
              <el-tab-pane label="全部">
                <el-form ref="repairForm4Ref" :model="repairForm4" label-width="50px" size="small">
                  <el-form-item label="搜索" prop="search" style="width: 50%">
                    <el-input v-model="repairForm1.search"></el-input>
                  </el-form-item>
                </el-form>
                <el-table :data="subTable5" style="width: 100%" border ref="subTable2Ref" @selection-change="subTable2Selected" :default-sort="{prop:'a',order:'ascending'}">
                  <el-table-column type="selection" width="35" />
                  <el-table-column prop="a" label="编码" width="100" />
                  <el-table-column prop="b" label="名称" />
                  <el-table-column prop="c" label="参考值" />
                  <el-table-column prop="d" label="报警值" />
                </el-table>
              </el-tab-pane>
              <el-tab-pane label="分组">
                <el-form ref="repairForm4Ref" :model="repairForm4" label-width="50px" size="small">
                  <div class="row-1">
                    <el-form-item label="搜索" prop="search" style="width: 50%">
                      <el-input v-model="repairForm1.search"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" size="mini">添加</el-button>
                    </el-form-item>
                  </div>
                </el-form>
                <el-table :data="subTable3" style="width: 100%" border ref="subTable3Ref" @selection-change="subTable3Selected" :default-sort="{prop:'a',order:'ascending'}">
                  <el-table-column type="selection" width="35" />
                  <el-table-column prop="a" label="巡检内容编码" />
                  <el-table-column prop="b" label="巡检内容名称" />
                  <el-table-column label="巡检步骤">
                    <template #default="scope">
                      <el-button type="text" @click="toogleExpand(scope.row)">[查看巡检步骤]</el-button>
                    </template>
                  </el-table-column>
                  <el-table-column type="expand" width="1">
                    <template #default>
                      <div style="padding:2vh">
                        <el-table :data="subTable5" style="width: 100%" border ref="subTable2Ref" @selection-change="subTable2Selected" :default-sort="{prop:'a',order:'ascending'}">
                          <el-table-column prop="a" label="编码" width="100" />
                          <el-table-column prop="b" label="名称" />
                          <el-table-column prop="c" label="步骤参考值" />
                          <el-table-column prop="d" label="报警关系" />
                        </el-table>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            </el-tabs>
            <div style="width:550px;margin-left:2vw">
              <div style="display:flex">
                <div style="line-height:30px;margin-right:1vw">已选中巡检步骤</div>
                <div>
                  <el-button type="primary" size="mini">全清</el-button>
                </div>
              </div>
              <el-table :data="subTable4" style="width: 500px" border ref="subTable4Ref" @selection-change="subTable4Selected" :default-sort="{prop:'a',order:'ascending'}">
                <el-table-column type="selection" width="35" />
                <el-table-column prop="a" label="巡检内容编码" />
                <el-table-column prop="b" label="巡检内容名称" />
                <el-table-column label="巡检步骤" width="160">
                  <template #default>
                    <el-button type="default">[查看巡检步骤]</el-button>
                  </template>
                </el-table-column>
                <el-table-column type="expand" width="1">
                  <template #default>
                    <div style="padding:3vh">
                      <el-table :data="subTable5" style="width: 100%;" border :default-sort="{ prop: 'a', order: 'ascending' }">
                        <el-table-column prop="a" label="步骤编码" />
                        <el-table-column prop="b" label="步骤名称" />
                        <el-table-column label="操作" width="160">
                          <template #default>
                            <el-button type="danger" size="mini">删除</el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairDialog4SureBtn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog4 = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- 弹出框：查看 -->
    <div v-dialogdrag>
      <el-dialog v-model="repairDialog2" title="查看" width="50%" @close="repairDialog2Close">
        <div class="dialog-border">
          <el-form label-width="80px" :model="repairForm2" ref="repairForm2Ref" :rules="repairForm2Rules" size="small">
            <div class="row-1">
              <el-form-item label="路线编号" prop="a" style="width:100%">
                <el-input v-model="repairForm2.a"></el-input>
              </el-form-item>
              <el-form-item label="路线名称" prop="b" style="width:100%">
                <el-input v-model="repairForm2.b"></el-input>
              </el-form-item>
              <el-form-item label="备注" prop="mark" style="width:100%">
                <el-input v-model="repairForm2.mark" type="textarea" :rows="1"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="dialog-border-padding">
            <div style="padding: 1vh 0;text-align:center">已选设备</div>
            <el-table :data="tableData1" style="width: 100%" border :default-sort="{ prop: 'a', order: 'ascending' }" :span-method="objectSpanMethod">
              <el-table-column prop="a" label="设备编号" />
              <el-table-column prop="b" label="设备名称" />
              <el-table-column prop="c" label="规格型号" />
              <el-table-column prop="d" label="安装地址" />
              <el-table-column prop="e" label="设备类型" />
              <el-table-column prop="f" label="步骤编码" />
              <el-table-column prop="g" label="步骤名称" />
            </el-table>
          </div>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="info" size="mini" @click="repairDialog2 = false">关闭</el-button>
          </span>
        </template>
      </el-dialog>
    </div>

    <!-- 弹出框：编辑 -->
    <div v-dialogdrag>
      <el-dialog v-model="repairDialog3" title="编辑" width="50%" @close="repairDialog3Close">
        <div class="dialog-border">
          <el-form label-width="100px" :model="repairForm3" ref="repairForm3Ref" :rules="repairForm3Rules" size="small">
            <div class="row-1">
              <el-form-item label="路线编号" prop="no" style="width:100%">
                <el-input v-model="repairForm3.no"></el-input>
              </el-form-item>
              <el-form-item label="路线名称" prop="no" style="width:100%">
                <el-input v-model="repairForm3.no"></el-input>
              </el-form-item>
            </div>
            <div style="padding: 0 2vw 0 0">
              <el-form-item label="备注" prop="mark" style="width:100%">
                <el-input v-model="repairForm3.mark" type="textarea" :rows="1"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="dialog-border-padding">
            <div style="padding: 1vh 0;text-align:center">已选设备</div>
            <div style="position:relative">
              <el-button type="primary" size="mini" style="position:absolute;right:0vw;bottom:0.5vh" @click="repairDialog1=true">增加</el-button>
            </div>
            <el-table :data="tableData" style="width: 100%" border :default-sort="{ prop: 'a', order: 'ascending' }">
              <el-table-column prop="a" label="设备编号" width="110" />
              <el-table-column prop="b" label="设备名称" />
              <el-table-column prop="c" label="规格型号" />
              <el-table-column prop="d" label="安装地址" />
              <el-table-column prop="e" label="设备类型" />
              <el-table-column label="操作" width="190">
                <template #default>
                  <el-button type="primary" size="mini">编辑巡检步骤</el-button>
                  <el-button type="danger" size="mini">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <template #footer>
          <span class="dialog-footer">
            <el-button type="primary" size="mini" @click="repairSureBtn">确定</el-button>
            <el-button type="info" size="mini" @click="repairDialog3 = false">取消</el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import Header from "@/components/Header";
import moment from "moment";
import LInput from "../../../components/LInput.vue";
import LDateTimeSelect2 from "../../../components/LDateTimeSelect2.vue";
import LButton from "../../../components/LButton.vue";
import LSelect from "@/components/LSelect.vue";

export default {
  components: {
    Header,
    LInput,
    LDateTimeSelect2,
    LButton,
    LSelect,
  },
  data() {
    return {
      name: "",
      type: [],
      option1: [
        {
          value: "1",
          label: "全部",
        },
        {
          value: "2",
          label: "冷水机组",
        },
        {
          value: "3",
          label: "循环水泵",
        },
        {
          value: "4",
          label: "冷却塔",
        },
        {
          value: "5",
          label: "电动阀门",
        },
        {
          value: "6",
          label: "空调箱",
        },
        {
          value: "7",
          label: "变压器",
        },
      ],
      tData: [
        {
          a: "DIC21062314002255",
          b: "冷水机组巡检",
          c: "冷水机组",
        },
      ],
      //=============================================
      repairDialog: false,
      repairForm: {},
      tableData: [
        {
          a: "1",
          b: "1",
          c: "1",
          d: "1",
          e: "1",
        },
      ],
      tableData1: [
        {
          a: "相同",
          b: "相同",
          c: "相同",
          d: "相同",
          e: "相同",
          f: "1f",
          g: "1g",
        },
        {
          a: "相同",
          b: "相同",
          c: "相同",
          d: "相同",
          e: "相同",
          f: "2f",
          g: "2g",
        },
        {
          a: "相同",
          b: "相同",
          c: "相同",
          d: "相同",
          e: "相同",
          f: "3f",
          g: "3g",
        },
      ],
      //==============================================
      repairDialog1: false,
      repairForm1: {},
      subTable1: [
        {
          a: "01",
          b: "大机房1#冷机",
          c: "",
          d: "主楼地下室大制冷机房",
          e: "冷水机组",
        },
        {
          a: "02",
          b: "大机房1#冷机2",
          c: "222",
          d: "主楼地下室大制冷机房2",
          e: "冷水机组2",
        },
      ],
      subTable1Select: null, //声明一个变量保存选择的值
      subTable5: [
        {
          a: "02",
          b: "检查机组运行噪声",
          c: "运行声音或震动是否正常",
          d: "是/否",
        },
        {
          a: "03",
          b: "检查机组运行噪声",
          c: "运行声音或震动是否正常",
          d: "是/否",
        },
      ],
      subTable2Select: null,
      subTable3: [
        {
          a: "DIC21062314002255",
          b: "冷水机组巡检",
        },
      ],
      subTable4: [
        {
          a: "03",
          b: "检查机组运转电流",
        },
        {
          a: "04",
          b: "空调机组运行数据",
        },
      ],
      //==============================================
      repairDialog2: false,
      repairForm2: {},

      repairDialog3: false,
      repairForm3: {},
      repairDialog4: false,
      repairForm4: {},
      subTable2: [],
    };
  },
  mounted() {},
  beforeUnmount() {},
  methods: {
    //清空筛选条件
    clearSelected() {
      console.log("点击清空按钮");
      this.name = "";
      this.type = "";
    },
    //=============================================
    //清空“新增”弹窗内容
    repairDialogClose() {
      this.$refs.repairFormRef.resetFields();
      this.tableData = [];
    },
    //"设备列表"当前选择值
    subTable1Selected(val) {
      console.log("选中项打印：", val);
      this.subTable1Select = val;
    },
    //"设备列表"清除当前选择值
    repairDialog1Close(rows) {
      this.$refs.repairForm1Ref.resetFields();
      if (rows) {
        rows.forEach((row) => {
          this.$refs.subTable1Ref.toggleRowSelection(row);
        });
      } else {
        this.$refs.subTable1Ref.clearSelection();
      }
    },
    // "设备列表"后“关闭”按钮
    repairDialog1CalcBtn(rows) {
      this.$refs.repairForm1Ref.resetFields();
      if (rows) {
        rows.forEach((row) => {
          this.$refs.subTable1Ref.toggleRowSelection(row);
        });
      } else {
        this.$refs.subTable1Ref.clearSelection();
      }
      this.repairDialog1 = false;
    },

    //"设备列表"后“确认”按钮
    repairDialog1SureBtn() {
      this.repairDialog1 = false;
      this.tableData.push(...this.subTable1Select);
      console.log("this.tableData2", this.tableData2);
    },
    //==============================================
    //"巡检步骤列表"当前选择值
    subTable2Selected(val) {
      console.log("选中项打印：", val);
      this.subTable2Select = val;
    },
    //"巡检步骤列表"清除当前选择值
    repairDialog4Close(rows) {
      this.$refs.repairForm4Ref.resetFields();
      if (rows) {
        rows.forEach((row) => {
          this.$refs.subTable2Ref.toggleRowSelection(row);
        });
      } else {
        this.$refs.subTable2Ref.clearSelection();
      }
    },
    // "巡检步骤列表"后“关闭”按钮
    repairDialog4CalcBtn(rows) {
      this.$refs.repairForm4Ref.resetFields();
      if (rows) {
        rows.forEach((row) => {
          this.$refs.subTable2Ref.toggleRowSelection(row);
        });
      } else {
        this.$refs.subTable2Ref.clearSelection();
      }
      this.repairDialog4 = false;
    },
    //"设备列表"后“确认”按钮
    repairDialog4SureBtn() {
      this.repairDialog4 = false;
      // this.tableData.push(...this.subTable1Select);
      // console.log("this.tableData2", this.tableData2);
    },
    //==============================================
    //"编辑"弹窗清空功能
    repairDialog3Close() {
      this.$refs.repairForm3Ref.resetFields();
      this.tableData = [];
    },
    //“编辑”窗口"步骤列表"后“确认”按钮
    repairDialog3SureBtn() {
      this.repairDialog1 = false;
      this.tableData.push(...this.subTable1Select);
      console.log("this.tableData2", this.tableData2);
    },
    //==============================================
    //删除数据按钮
    del() {
      this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          // post("/airChannel/deleteAirChannel", { id: id }).then((res) => {
          //   // console.log(res);
          //   if (res.data.code == 200) {
          //     this.$message.success(res.data.data);
          //     this.getData();
          //   } else {
          //     this.$message.error(res.data.data);
          //   }
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //===============================================
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 0) {
      //   if (rowIndex % 2 === 0) {
      //     return {
      //       rowspan: 2,
      //       colspan: 1,
      //     };
      //   } else {
      //     return {
      //       rowspan: 0,
      //       colspan: 0,
      //     };
      //   }
      // }

      this.tableData1.map((item, index, value) => {
        return console.log(item, index, value);
      });
    },
    //===================================================
    toogleExpand(row) {
      console.log(row);
      let $table = this.$refs.subTable3Ref;
      // this.tData.map((item) => {
      //   if (row.id != item.id) {
      //     $table.toggleRowExpansion(item, false);
      //   }
      // });
      $table.toggleRowExpansion(row);
    },
    //===================================================
  },
};
</script>


<style lang="less" scoped>
@import "../opera.less";

.search_bar {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

/deep/ .el-dialog .el-select {
  width: 360px;
}

.row-1 {
  display: flex;
  justify-content: space-between;
  padding: 0 2vw 0 0;
}

.pop-2 {
  /deep/.el-tabs__nav-scroll {
    background-color: rgba(22, 35, 70, 1); //标签分类块颜色
  }
  /deep/.el-tabs--border-card {
    background: rgba(255, 255, 255, 0.1);
  }
  /deep/.el-tabs--border-card > .el-tabs__header .el-tabs__item.is-active {
    background: rgba(255, 255, 255, 0.1); //标签分类颜色
  }
}
</style>